$(document).ready(function (e) {
    var $loginForm = $('#loginForm').bootstrapValidator({
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            username: {
                validators: {
                    stringLength: {
                        max: 15,
                        min: 4,
                        message: '用户名最小4位字符，最长15位字符'
                    }
                }
            },
            password: {
                validators: {
                    stringLength: {
                        max: 30,
                        min: 6,
                        message: '密码最小6位字符，最长30位字符'
                    }
                }
            }
        }
    }).on('success.form.bv', function (e) {
        e.preventDefault();
        var username = $("input[name=username]", $loginForm).val();
        var password = $("input[name=password]", $loginForm).val();
        $.loginModal.doLogin(username, password, function (user) {
            createCookie("login.username", username, 100);
            $.loginModal.loginHide();
        });
    });
    $("#loginForm input[name=username]").val(readCookie("login.username") || '');
});